<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="content">
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>
            <h:form id="userView"  prependId="false">
                <p:panel header="Coming Purchase Order" style="text-align: center">
                    <p:dataTable  value="#{rawMaterialPurchaseOrderEntityController.rpos}" var="rmq" widgetVar="userTable"
                                  paginator="true" rows="10"  
                                  paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                                  >     


                        <p:column sortBy="#{rmq.rmq.vendor.companyName}" filterBy="#{rmq.rmq.vendor.companyName}">    <f:facet name="header">  
                                <h:outputText value="Order from:" /> </f:facet>
                            <h:outputText value="#{rmq.rmq.vendor.companyName}" /> </p:column>
                        <p:column sortBy="#{rmq.rmq.rawMaterial.productName}" filterBy="#{rmq.rmq.rawMaterial.productName}">    <f:facet name="header">  
                                <h:outputText value="Raw material :" /> </f:facet>
                            <h:outputText value="#{rmq.rmq.rawMaterial.productName}" /> </p:column>    
                        <p:column sortBy="#{rmq.quantity}" filterBy="#{rmq.quantity}">    <f:facet name="header">  
                                <h:outputText value="Total Amount :" /> </f:facet>
                            <h:outputText value="#{rmq.quantity}" /> </p:column>
                        <p:column sortBy="#{rmq.amountLeft}" filterBy="#{rmq.amountLeft}">    <f:facet name="header">  
                                <h:outputText value= "Amount Left:" /> </f:facet>
                            <h:outputText value="#{rmq.amountLeft}" /> </p:column>
                        <p:column sortBy="#{rmq.status}" filterBy="#{rmq.status}">    <f:facet name="header">  
                                <h:outputText value="Status" /> </f:facet>
                            <h:outputText value="#{rmq.status}" /> </p:column>
                        <p:column>    <f:facet name="header">  
                                <h:outputText value="Date Purchased:" /> </f:facet>
                            <h:outputText value="#{rmq.createdAt}" > 
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                        </p:column>

                        <p:column>

                            <p:commandButton value="More Info"  update="display" oncomplete="customerDialog.show()">
                                <f:setPropertyActionListener value="#{rmq}"  
                                                             target="#{rawMaterialPurchaseOrderEntityController.po}" /> 
                            </p:commandButton>
                        </p:column>
                        <p:column>

                            <p:commandButton disabled="#{rmq.amountLeft == 0}" value="Acknowledge Shipment" ajax ="false" action="MaintainOrder" >

                                <f:setPropertyActionListener value="#{rmq}"  
                                                             target="#{rawMaterialPurchaseOrderEntityController.currPurchaseOrder}" /> 
                            </p:commandButton>
                        </p:column>
                    </p:dataTable> 
                </p:panel>
                <br/>
                <p:dialog header="Order Information:" widgetVar="customerDialog" resizable="false"  
                          width="325" showEffect="explode" hideEffect="explode"> 
               
                        <h:panelGrid id="display" columns="2" cellpadding="4"> 


                            <h:outputText value="Total Cost:"/>

                            <h:outputText value="#{rawMaterialPurchaseOrderEntityController.po.cost}"/>



                            <h:outputText value="Order initiated by:"/>
                            <h:outputText value="#{rawMaterialPurchaseOrderEntityController.po.createdBy.name}"/>  


                            <p:separator/>
                            <br/>
                            <h:outputText value="Scheduled Shipment of this order:"/>
                            <br/>
                            <p:dataTable value="#{rawMaterialPurchaseOrderEntityController.scheduleShip1}" var="entry" >
                                <p:column>
                                    <f:facet name="header" >
                                        <h:outputText value="Shipment date:"/>
                                    </f:facet>
                                    <p:dataTable value="#{entry}" var="type" >
                                        <p:column>

                                            <h:outputText value="#{type.key}">
                                                <f:convertDateTime pattern="dd/MM/yyyy" />
                                            </h:outputText>

                                        </p:column>
                                    </p:dataTable>
                                </p:column>
                                <p:column>
                                    <f:facet name="header" >
                                        <h:outputText value="Amount:"/>
                                    </f:facet>
                                    <p:dataTable value="#{entry}" var="type" >
                                        <p:column>

                                            <h:outputText value="#{type.value}"/>

                                        </p:column>
                                    </p:dataTable>
                                </p:column>



                            </p:dataTable>

                            <br/>
                            <p:separator/>
                            <br/>      
                            <br/>
                        </h:panelGrid> 
            
                </p:dialog>
            </h:form>
        </ui:define>
    </ui:composition>

</html>